package com.powernode.cudops;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ResourceBundle;

/**
 * @Author Arrebol
 * @Date 2024/7/31 22:43
 * @Project jdbc
 * @Description： 使用JDBC程序jabc.t_user实现修改操作
 */
public class JdbcTest5 {
    public static void main(String[] args) {
        ResourceBundle bundle = ResourceBundle.getBundle("jdbc");
        String driver = bundle.getString("driver");
        String url = bundle.getString("url");
        String user = bundle.getString("user");
        String password = bundle.getString("password");
        Connection conn = null;
        Statement stmt = null;
        try {
            Class.forName(driver);
            conn = DriverManager.getConnection(url, user, password);
            stmt = conn.createStatement();
            String sql="update t_user set username = 'wangwu',password='123123',real_name='武王'," +
                    "gender='男',tel='1300000000' where username='lisi'";
            int count = stmt.executeUpdate(sql);
            System.out.println("修改了"+count+"条记录");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            try {
                if (conn != null) {
                    conn.close();
                }
                if (stmt != null) {
                    stmt.close();
                }
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }
}
